/* Copyright (C) 2008 Nick Crafford <nickcrafford@earthlink.net>
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
var image = /[jpg|gif|png|jpeg|JPG|GIF|PNG|JPEG]/;

function gameAlert(x,y,width,height,color) {

    var div;

    this.x      = x;
    this.y      = y;
    this.width  = width;
    this.height = height;
    this.color  = color;

    this.show = function(text)
    {
        var tDiv        = window.document.createElement('div');

        var colorString = '';

        if(image.exec(this.color))
        {
            colorString = 'background-image:url('+this.color+');';
        }
        else if(this.color == '')
        {
            colorString = '';
        }
        else
        {
            colorString = 'background-color:'+this.color+';';
        }

        var styleString = 'position:absolute;'+
                          colorString +
                          'width:'  +this.width + ';' +
                          'height:' +this.height + ';' +
                          'left:'   +this.x      + ';' +
                          'top:'    +this.y      + ';' +
                          'text-align:left;'   +
                          'color:white;'         +
                          'font-size:14px;'      +
                          'border-top:    4px solid ;' +
                          'border-bottom: 4px solid ;' +
                          'border-left:   4px solid ;' +
                          'border-right:  4px solid ;' +
                          'border-color: #DDDCDA;' +
                          'padding-top: 10px;' +
                          'padding-bottom: 10px;' +
                          'padding-left: 10px;' +
                          'padding-right: 10px;' +
                          'font-family:monospace;';

        tDiv.setAttribute('style',styleString);

        var tNode = window.document.createElement('span');
        tNode.setAttribute('style', 'font-color:#FFFFFF;')
        tNode.innerHTML = text;

        tDiv.appendChild(tNode);
        tDiv.setAttribute('id', Math.ceil(Math.random()*10000));

        document.body.appendChild(tDiv);

        div = tDiv;
    }

    this.changeOpacity = function(amount)
    {
        div.style.MozOpacity=amount;
    }

    this.close = function(time)
    {
        if(time != '')
        {
            var self = this;
            setTimeout(function(){document.body.removeChild(div);}, time)
        }
        else
        {
            document.body.removeChild(div);
        }
    }
}
